home *** CD-ROM | disk | FTP | other *** search
- /*
- * CustomIO_Lib.c
- *
- * Demo/Template for writing custom IO functions
- *
- * Custom Attribute example
- */
- #include "QD3D.h"
- #include "QD3DPick.h"
- #include "QD3DSet.h"
- #include "QD3DIO.h"
- #include "QD3DGroup.h"
- #include "WWWAnchorIO_Lib.h"
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
-
- /*
- * Globals
- */
- static TQ3ObjectClass gWWWAnchorClass;
-
- /*
- * Public Functions
- */
- TQ3Boolean WWWAnchor_GetFromObject(
- TQ3Object object,
- WWWAnchorData *data)
- {
- TQ3SetObject set;
- TQ3Boolean result;
-
- data->url = NULL;
-
-
- if ((Q3Object_IsType(object, kQ3ShapeTypeGeometry) == kQ3False) &&
- (Q3Object_IsType(object, kQ3ShapeTypeGroup) == kQ3False))
- return kQ3False;
-
- if (Q3Shape_GetSet(object, &set) == kQ3Failure)
- return kQ3False;
-
- if (set == NULL)
- return kQ3False;
-
- result =
- (Q3Set_Contains(set, kElementTypeWWWAnchor) == kQ3False) ||
- (Q3Set_Get(set, kElementTypeWWWAnchor, data) == kQ3Failure) ||
- (data->url == NULL) ?
- kQ3False : kQ3True;
-
- Q3Object_Dispose(set);
-
- return result;
- }
-
- TQ3Boolean WWWAnchor_GetFromHitData(
- const TQ3HitData *hitData,
- WWWAnchorData *data)
- {
- /* When the original group is given, add this code:
-
- TQ3GroupObject group, nextGroup;
- TQ3GroupPosition *pos;
- long nPos, i;
-
- if (hitData->validMask & kQ3PickDetailMaskPath)
- {
-
- group = hitData->path.rootGroup;
- pos = hitData->path.positions;
- nPos = hitData->path.depth;
-
- Q3Shared_GetReference(group);
-
- for (i = 0; i < nPos; i++)
- {
- if (WWWAnchor_GetFromObject(group, data) == kQ3True)
- return kQ3True;
- if (Q3Group_GetPositionObject(group, pos[i], &nextGroup) == kQ3Failure)
- break;
- Q3Object_Dispose(group);
- group = nextGroup;
- }
-
- Q3Object_Dispose(group);
- }
-
- */
- return WWWAnchor_GetFromObject(hitData->object, data);
- }
-
- /* If the above return kQ3True, call this when you're done with the data */
-
- void WWWAnchor_Empty(
- WWWAnchorData *data)
- {
- if (data->url != NULL) {
- free(data->url);
- data->url = NULL;
- }
- }
-
- /*
- * Static Functions
- */
- static TQ3Status WWWAnchor_Traverse(
- WWWAnchorData *wwwdata,
- TQ3FileObject file)
- {
- TQ3Size size;
-
- if (wwwdata->url == NULL)
- return kQ3Success;
-
- size = Q3Size_Pad(strlen(wwwdata->url) + 1);
-
- return
- Q3View_SubmitWriteData(file, size, wwwdata, NULL);
-
- //return
- // Q3FileWriteState_SetObjectWriteData(
- // file, wwwdata, size);
- }
-
- static TQ3Status WWWAnchor_Write(
- WWWAnchorData *wwwdata,
- TQ3FileObject file)
- {
- return
- Q3String_Write(wwwdata->url, file) == kQ3Success &&
- Q3Comment_Write("url", file) == kQ3Success ? kQ3Success : kQ3Failure;
- }
-
- static TQ3Status WWWAnchor_ReadData(
- TQ3SetObject set,
- TQ3FileObject file)
- {
- char buf[kQ3StringMaximumLength];
- WWWAnchorData wwwdata;
-
- if (Q3String_Read(buf, NULL, file) == kQ3Failure)
- return kQ3Failure;
-
- wwwdata.url = buf;
-
- return Q3Set_Add(set, kElementTypeWWWAnchor, &wwwdata);
- }
-
- static TQ3Status WWWAnchor_CopyAdd(
- WWWAnchorData *src,
- WWWAnchorData *dst)
- {
- long i;
-
- if (src->url == NULL)
- return kQ3Failure;
-
- i = strlen(src->url);
-
- if (i == 0)
- return kQ3Failure;
-
- dst->url = malloc(i + 1);
-
- if (dst->url == NULL)
- return kQ3Failure;
-
- strcpy(dst->url, src->url);
-
- return kQ3Success;
- }
-
- static TQ3Status WWWAnchor_CopyReplace(
- WWWAnchorData *src,
- WWWAnchorData *dst)
- {
- long i;
- char *c;
-
- if (src->url == NULL)
- return kQ3Failure;
-
- i = strlen(src->url);
-
- if (i == 0)
- return kQ3Failure;
-
- c = realloc(dst->url, i + 1);
-
- if (c == NULL)
- return kQ3Failure;
-
- dst->url = c;
-
- strcpy(dst->url, src->url);
-
- return kQ3Success;
- }
-
- static TQ3Status WWWAnchor_Delete(
- WWWAnchorData *src)
- {
- if (src->url != NULL)
- free(src->url);
-
- return kQ3Success;
- }
-
- /*
- * WWWAnchor_MetaHandler
- */
- static TQ3FunctionPointer WWWAnchor_MetaHandler(
- TQ3MethodType methodType)
- {
- switch (methodType)
- {
- case kQ3MethodTypeObjectTraverse:
- return (TQ3FunctionPointer) WWWAnchor_Traverse;
- case kQ3MethodTypeObjectWrite:
- return (TQ3FunctionPointer) WWWAnchor_Write;
- case kQ3MethodTypeObjectReadData:
- return (TQ3FunctionPointer) WWWAnchor_ReadData;
- case kQ3MethodTypeElementCopyAdd:
- case kQ3MethodTypeElementCopyGet:
- case kQ3MethodTypeElementCopyDuplicate:
- return (TQ3FunctionPointer) WWWAnchor_CopyAdd;
- case kQ3MethodTypeElementCopyReplace:
- return (TQ3FunctionPointer) WWWAnchor_CopyReplace;
- case kQ3MethodTypeElementDelete:
- return (TQ3FunctionPointer) WWWAnchor_Delete;
- default:
- return (TQ3FunctionPointer) NULL;
- }
- }
-
- /*
- * WWWAnchor_Register
- */
- TQ3Status WWWAnchor_Register(
- void)
- {
- gWWWAnchorClass =
- Q3ElementClass_Register(
- kElementTypeWWWAnchor,
- kElementNameWWWAnchor,
- sizeof(WWWAnchorData),
- WWWAnchor_MetaHandler);
-
- return (gWWWAnchorClass == NULL ? kQ3Failure : kQ3Success);
- }
-
- TQ3Status WWWAnchor_UnRegister(
- void)
- {
- return Q3ObjectClass_Unregister(gWWWAnchorClass);
- }